package com.mypage.view.datedialog;

import android.content.Context;
import android.view.Gravity;
import android.widget.Button;
import android.widget.TextView;

import com.mypage.view.datedialog.DateTimePopupWindow.OnTimeSelectListener;
import com.mypage.view.datedialog.DateTimePopupWindow.Type;

import java.text.SimpleDateFormat;
import java.util.Date;


public class DateTimeUtil {
	private static onCallBackListener onCallBackListener;
	public static String selectTime = "ѡ��ʱ��";
	public static SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	public static SimpleDateFormat format_s = new SimpleDateFormat("yyyy-MM-dd");
	public static SimpleDateFormat format_m = new SimpleDateFormat("yyyy-M");
	/** ʱ��ѡ��popupwindow */
	public static void initSelectTimePopuwindow(Context context,final Button button, boolean isBefore) {
		DateTimePopupWindow timePopupWindow = new DateTimePopupWindow("E",context,Type.ALL);
		timePopupWindow.setCyclic(true);
		// ʱ��ѡ���ص�
		timePopupWindow.setOnTimeSelectListener(new OnTimeSelectListener() {

			@Override
			public void onTimeSelect(Date date) {
				selectTime = getTime(date);
				button.setText(selectTime);
			}
		});
		timePopupWindow.showAtLocation(button, Gravity.BOTTOM, 0, 0,new Date(), isBefore);
	}
	public static void initSelectTimePopuwindow_s(Context context,final Button button, boolean isBefore) {
		DateTimePopupWindow timePopupWindow = new DateTimePopupWindow("T",context,Type.ALL);
		timePopupWindow.setCyclic(true);
		// ʱ��ѡ���ص�
		timePopupWindow.setOnTimeSelectListener(new OnTimeSelectListener() {

			@Override
			public void onTimeSelect(Date date) {
				selectTime = getTime_s(date);
				button.setText(selectTime);
			}
		});
		timePopupWindow.showAtLocation(button, Gravity.BOTTOM, 0, 0,new Date(), isBefore);
	}

	public static void initSelectTimePopuwindow_m(Context context, final TextView textView, boolean isBefore) {
		DateTimePopupWindow timePopupWindow = new DateTimePopupWindow("M",context,Type.ALL);
		timePopupWindow.setCyclic(true);
		// ʱ��ѡ���ص�
		timePopupWindow.setOnTimeSelectListener(new OnTimeSelectListener() {

			@Override
			public void onTimeSelect(Date date) {
				selectTime = getTime_m(date);
				if(onCallBackListener != null)
				{
					onCallBackListener.onTimeSelect(selectTime);
				}
			}
		});
		timePopupWindow.showAtLocation(textView, Gravity.BOTTOM, 0, 0,new Date(), isBefore);
	}

	public static String getTime(Date date) {
		return format.format(date);
	}
	public static String getTime_s(Date date) {
		return format_s.format(date);
	}
	public static String getTime_m(Date date) {
		return format_m.format(date);
	}

	public interface onCallBackListener
	{
		public void onTimeSelect(String date);
	}

	public void setOnCallBackListener(onCallBackListener onCallBackListener)
	{
		this.onCallBackListener = onCallBackListener;
	}
}
